package com.jml.三期.HashMap;

import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;


public class Test003 {
    public static void main(String[] args) {
        int aa = (int) (2*0.75);
        System.out.println(aa);
        HashMap<String, String> hashMap = new HashMap<>();
        for (int i = 1; i < 100; i++) {
            hashMap.put(i + "", i + "");
        }
        hashMap.forEach((k, v) -> {
            System.out.println("k:" + k + "v:" + v);
        });
//        new Object();
//
//        new LinkedHashMap<>();
        System.out.println(8 >> 2);
        // 8 二进制 右移动两位
        //0000 1000
        //0000 0010--二进制 转换10 2
        System.out.println(10>>2);
        System.out.println(8>>2);
        System.out.println(10<<2);
        System.out.println(10 >>> 2);
        ConcurrentHashMap<Object, Object> concurrentHashMap = new ConcurrentHashMap<>();
        concurrentHashMap.put("","");
    }

    //hashCode方法是C语言编写的，HashCode的值是在根据对象的内存地址来的，然后转换为整数类型
    //equals方法如果两个对象的hashCode值相等，则两个对象的内容值不一定相等
    //如果使用equals方法去比较两个对象的内容值，相等的情况下则两个对象的HashCode一定相等。
    //两个对象的equals相等则hashCode一定相等，hashCode相等，equals不一定相等。
    static final int hash(Object key) {
        int h;
        return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);
    }


    final V putVal(K key, V value, boolean onlyIfAbsent) {
        if (key == null || value == null) throw new NullPointerException();
        int hash = spread(key.hashCode());
        int binCount = 0;
        for (ConcurrentHashMap.Node<K,V>[] tab = table;;) {
            ConcurrentHashMap.Node<K,V> f; int n, i, fh;
            if (tab == null || (n = tab.length) == 0)
                tab = initTable();
            else if ((f = tabAt(tab, i = (n - 1) & hash)) == null) {
                if (casTabAt(tab, i, null,
                        new ConcurrentHashMap.Node<K,V>(hash, key, value, null)))
                    break;                   // no lock when adding to empty bin
            }
            else if ((fh = f.hash) == MOVED)
                tab = helpTransfer(tab, f);
            else {
                V oldVal = null;
                synchronized (f) {
                    if (tabAt(tab, i) == f) {
                        if (fh >= 0) {
                            binCount = 1;
                            for (ConcurrentHashMap.Node<K,V> e = f;; ++binCount) {
                                K ek;
                                if (e.hash == hash &&
                                        ((ek = e.key) == key ||
                                                (ek != null && key.equals(ek)))) {
                                    oldVal = e.val;
                                    if (!onlyIfAbsent)
                                        e.val = value;
                                    break;
                                }
                                ConcurrentHashMap.Node<K,V> pred = e;
                                if ((e = e.next) == null) {
                                    pred.next = new ConcurrentHashMap.Node<K,V>(hash, key,
                                            value, null);
                                    break;
                                }
                            }
                        }
                        else if (f instanceof ConcurrentHashMap.TreeBin) {
                            ConcurrentHashMap.Node<K,V> p;
                            binCount = 2;
                            if ((p = ((ConcurrentHashMap.TreeBin<K,V>)f).putTreeVal(hash, key,
                                    value)) != null) {
                                oldVal = p.val;
                                if (!onlyIfAbsent)
                                    p.val = value;
                            }
                        }
                    }
                }
                if (binCount != 0) {
                    if (binCount >= TREEIFY_THRESHOLD)
                        treeifyBin(tab, i);
                    if (oldVal != null)
                        return oldVal;
                    break;
                }
            }
        }
        addCount(1L, binCount);
        return null;
    }
}
